package com.haier.cloudremote.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.haier.cloudremote.R;
import com.haier.cloudremote.model.HDMIInfo;

public class HDMIAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<HDMIInfo> hdmiInfos = new ArrayList<HDMIInfo>();
	private LayoutInflater inflater;	
	
	public HDMIAdapter(Context context, ArrayList<HDMIInfo> hdmiInfos) {
		super();
		this.context = context;
		this.hdmiInfos = hdmiInfos;
		inflater = (LayoutInflater) context.getSystemService
				(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return hdmiInfos.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return hdmiInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		TextView textView; 
		HDMIInfo hdmiInfo = (HDMIInfo)getItem(position);
		if(convertView==null){
			convertView = inflater.inflate
					(R.layout.listitem, null);
			textView = (TextView)convertView.findViewById(R.id.listitem_textView);
			convertView.setTag(textView);
			
		}else{
			textView = (TextView)convertView.getTag();
		}
		textView.getLayoutParams().height = (int)context.getResources().getDimension(R.dimen.list_item_height);
		
		textView.setText(hdmiInfo.getHdmiName());
		textView.setTextColor(Color.BLACK);
		textView.setTextSize((int)context.getResources().getDimension(R.dimen.list_item_textsize));
		
		return convertView;
	}

}
